set more 1
clear

pause off 

capture log close


global dir_tab_out     "../outputs"
global dir_work_out    "out_figs" 

******************************************************************
******************************************************************
global inout "_CF_EducPlus_3"
global  dir_cfdata   	"out_files$inout"  
global  dir_basedata    "out_files" 


use $dir_cfdata/sim_model_part1, clear
gen hgc = educ 

rename * cf_*
rename cf_id  id 
rename cf_age age
*rename cf_cat_theta* cat_theta* 

merge 1:1 id age using $dir_basedata/sim_model_part1
gen hgc = educ 
keep if _merge == 3

sum age 
sort id age
by id: egen inithgc = min(hgc)



keep if age == 30 
keep if dq == 1


capture drop quitter
gen quitter = (cf_dq==0) 
probit quitter  thetac thetan inithgc 
local my_r2_p = e(r2_p) 
margins, dydx(  thetac thetan inithgc ) atmeans post

estadd scalar my_r2_p = `my_r2_p', replace	
eststo regcf1 





******************************************************************
******************************************************************
global inout "_optTax"
global  dir_cfdata   	"out_files$inout"  
global  dir_basedata    "out_files"


use $dir_cfdata/sim_model_part1, clear
gen hgc = educ 

rename * cf_*
rename cf_id  id 
rename cf_age age
*rename cf_cat_theta* cat_theta* 

merge 1:1 id age using $dir_basedata/sim_model_part1
gen hgc = educ 
keep if _merge == 3

sum age 
sort id age
by id: egen inithgc = min(hgc)



keep if age == 30 
keep if dq == 1


capture drop quitter
gen quitter = (cf_dq==0) 
probit quitter  thetac thetan inithgc 
local my_r2_p = e(r2_p) 
margins, dydx(  thetac thetan inithgc ) atmeans post

estadd scalar my_r2_p = `my_r2_p', replace	
eststo regcf3


******************************************************************
******************************************************************

	** Table 5: report coef for thetac and thetan 
    ** reduction of smoking: under "_CF_EducPlus_3" and "_optTax" 
    quietly esttab regcf1 regcf3  using $dir_work_out/cfreg_quitter.tex, keep(thetac thetan) margin replace stats(N my_r2_p, fmt(%9.0fc %9.3f) labels("Observations""Pseudo R2"))  b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) label title(Effects on quitting smoking in the counterfactual experiments \label{cfreg:quitter} ) nogaps compress `option' nomtitles
    quietly esttab regcf1 regcf3  using $dir_tab_out/Table_05.tex, keep(thetac thetan) margin replace stats(N my_r2_p, fmt(%9.0fc %9.3f) labels("Observations""Pseudo R2"))  b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) label title(Effects on quitting smoking in the counterfactual experiments \label{cfreg:quitter} ) nogaps compress `option' nomtitles

